rm(list=ls())
setwd("~/Dropbox/Legislators Voting/Overtime_Replication/")

library(ggplot2)
library(maps)
library(foreign)
library(reshape2)
library(RColorBrewer)
library(mapproj)
library(car)

overtime <- read.dta("EnvOpinion_19732012.dta")

#### Creating Decade-Level Data ####

overtime_decade <- overtime
overtime_decade$period <- ""
overtime_decade[which(overtime_decade$year> 1972 & overtime_decade$year < 1983),]$period <- "year_73_82"
overtime_decade[which(overtime_decade$year> 2002 & overtime_decade$year < 2013),]$period <- "year_03_12"

overtime_decade$region <-  tolower(overtime$state_full)

overtime_decade <- within(overtime_decade, {mean_pro = ave(env_pro, region, period)})
overtime_decade <- within(overtime_decade, {mean_dem_pro = ave(env_dem_whosay_pro, region, period)})
overtime_decade <- within(overtime_decade, {mean_gop_pro = ave(env_gop_whosay_pro, region, period)})
overtime_decade <- within(overtime_decade, {mean_ind_pro = ave(env_ind_whosay_pro, region, period)})

overtime_decade <- within(overtime_decade, {mean_anti = ave(env_anti, region, period)})
overtime_decade <- within(overtime_decade, {mean_dem_anti = ave(env_dem_whosay_anti, region, period)})
overtime_decade <- within(overtime_decade, {mean_gop_anti = ave(env_gop_whosay_anti, region, period)})
overtime_decade <- within(overtime_decade, {mean_ind_anti = ave(env_ind_whosay_anti, region, period)})

overtime_decade <- within(overtime_decade, {mean_dem = ave(dem, region, period)})
overtime_decade <- within(overtime_decade, {mean_gop = ave(gop, region, period)})
overtime_decade <- within(overtime_decade, {mean_ind = ave(ind, region, period)})

overtime_decade <- overtime_decade[which(overtime$year==1973|overtime$year==2003),c("state_abb", "state_id", "state_full", "region", "period", "mean_pro", "mean_dem_pro", "mean_gop_pro", "mean_ind_pro", "mean_anti", "mean_dem_anti", "mean_gop_anti", "mean_ind_anti", "mean_dem", "mean_gop", "mean_ind")]

perc.rank <- function(x) trunc(rank(x))/length(x) # calculating percentage rank
overtime_decade$pro_10_pt <- perc.rank(overtime_decade$mean_pro)
overtime_decade$anti_10_pt <- perc.rank(overtime_decade$mean_anti)

overtime_decade <- reshape(overtime_decade, timevar = "period", idvar = c("state_abb", "state_id", "state_full", "region"), direction = "wide")
names(overtime_decade) <- gsub(".year", "", names(overtime_decade))

overtime_decade$pro_change <- overtime_decade$mean_pro_03_12 - overtime_decade$mean_pro_73_82
overtime_decade$anti_change <- overtime_decade$mean_anti_03_12 - overtime_decade$mean_anti_73_82

overtime_decade$pro_dem_change <- overtime_decade$mean_dem_pro_03_12 - overtime_decade$mean_dem_pro_73_82
overtime_decade$pro_gop_change <- overtime_decade$mean_gop_pro_03_12 - overtime_decade$mean_gop_pro_73_82
overtime_decade$pro_ind_change <- overtime_decade$mean_ind_pro_03_12 - overtime_decade$mean_ind_pro_73_82

overtime_decade$anti_dem_change <- overtime_decade$mean_dem_anti_03_12 - overtime_decade$mean_dem_anti_73_82
overtime_decade$anti_gop_change <- overtime_decade$mean_gop_anti_03_12 - overtime_decade$mean_gop_anti_73_82
overtime_decade$anti_ind_change <- overtime_decade$mean_ind_anti_03_12 - overtime_decade$mean_ind_anti_73_82

overtime_decade$dem_change <- overtime_decade$mean_dem_03_12 - overtime_decade$mean_dem_73_82
overtime_decade$gop_change <- overtime_decade$mean_gop_03_12 - overtime_decade$mean_gop_73_82
overtime_decade$ind_change <- overtime_decade$mean_ind_03_12 - overtime_decade$mean_ind_73_82

# Adding Map-Related Information to Decade Data

all_states <- map_data("state")
all_states <- all_states[all_states$region!="district of columbia",]
data_map <- merge(all_states, overtime_decade, by="region")

#### Figure 1 ####

# Note: Due to the agreement with the GSS survey data, we can't share the individual-level raw GSS data with information on respondents' states of residence. As Figure 1 requires using the raw data, we do not provide code for generating Figure 1.

#### Figure 2 ####

df_overtime <- overtime[c("env_pro", "env_anti", "state_abb", "year")]
df_overtime <- melt(df_overtime, id.vars = c("state_abb", "year"))

ggplot(df_overtime, aes(x=year, y=value, colour=variable)) + geom_point(shape=20, size = 2.5) + labs(x="Year", y = "Environmental Opinion") + 
  ylim(0.0,1.0) + theme_bw() + theme(axis.title.y = element_text(size = rel(1.2), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.2), angle = 00)) + 
  scale_colour_manual(values = c("env_pro" = "gray60", "env_anti" = "gray0"), labels=c("Pro-Environment", "Anti-Environment"), name = "") + theme(legend.position="bottom")

ggsave("Figure2_Overtime.pdf", width=6, height=6)

#### Figure 3 ####

# Map with Pro-Enviornmental Opinion in 1973-1982 

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=pro_10_pt_73_82), colour="white") + scale_fill_continuous(name = "Proportion", low="white", high="darkgreen", guide="colorbar", limits=c(0.0,1.0), labels=c("0.45", "0.54", "0.58", "0.61", "0.67")) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm")) 

ggsave("Figure3A_1973_82.pdf", width=11, height=5)

# Map with Pro-Enviornmental Opinion in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=pro_10_pt_03_12), colour="white") + scale_fill_continuous(name = "Proportion", low="white", high="darkgreen", guide="colorbar", limits=c(0.0,1.0), labels=c("0.45", "0.54", "0.58", "0.61", "0.67")) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm")) 

ggsave("Figure3B_1973_82.pdf", width=11, height=5)

# Map with Change in Pro-Enviornmental Opinion 

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=pro_change), colour="white") + scale_fill_gradient2(name = "Change in \nProportion", low="red",mid="white",high="blue",midpoint=0, limits=c(-0.12,0.12)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Pro-Environment Opinion", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("Figure3C_Change.pdf", width=11, height=5)

#### Figure 4 ####

ggplot(overtime_decade, aes(x=mean_pro_73_82, y=mean_pro_03_12)) + geom_point(shape=20, size=2.5) + labs(x="10-Year Average Pro-Environment Opinion in 1973-82", y = "10-Year Average Pro-Environment Opinion in 2003-12") + 
  xlim(0.4,0.7) + ylim(0.4,0.7) + geom_smooth(colour="black") + theme_bw() + theme(axis.title.y = element_text(size = rel(1.25), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.25), angle = 00)) + geom_abline(slope = 1, colour='grey')

ggsave("Figure4_Pro.pdf", width=6, height=6)

ggplot(overtime_decade, aes(x=mean_anti_73_82, y=mean_anti_03_12)) + geom_point(shape=20, size=2.5) + labs(x="10-Year Average Anti-Environment Opinion in 1973-82", y = "10-Year Average Anti-Environment Opinion in 2003-12") + 
  xlim(0.07,0.148) + ylim(0.07,0.148) + geom_smooth(colour="black") + theme_bw() + theme(axis.title.y = element_text(size = rel(1.25), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.25), angle = 00)) +geom_abline(slope = 1, colour='grey')

ggsave("Figure4_Anti.pdf", width=6, height=6)

#### Figure 5 ####

pro_df <- overtime[c("env_dem_whosay_pro", "env_gop_whosay_pro", "env_ind_whosay_pro", "state_abb", "year")]
pro_df$difference <- pro_df$env_dem_whosay_pro - pro_df$env_gop_whosay_pro
pro_df <- melt(pro_df, id.vars = c("state_abb", "year"))

anti_df <- overtime[c("env_dem_whosay_anti", "env_gop_whosay_anti", "env_ind_whosay_anti", "state_abb", "year")]
anti_df$difference <- anti_df$env_gop_whosay_anti - anti_df$env_dem_whosay_anti
anti_df <- melt(anti_df, id.vars = c("state_abb", "year"))

ggplot(pro_df[which(pro_df$variable!="difference"),], aes(x=year, y=value, colour=variable)) + geom_point(shape=20) + labs(x="Year", y = "Pro-Environment Opinion") + 
  ylim(0.0,1.0) + theme_bw() + theme(axis.title.y = element_text(size = rel(1.2), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.2), angle = 00)) + 
  scale_colour_manual(values = c("env_dem_whosay_pro" = "gray80", "env_gop_whosay_pro" = "gray10", "env_ind_whosay_pro" = "gray40"), labels=c("Democrats", "Republicans", "Independents"), name = "") + theme(legend.position="bottom")

ggsave("Figure5A_Pro.pdf", width=6, height=6)

ggplot(anti_df[which(pro_df$variable!="difference"),], aes(x=year, y=value, colour=variable)) + geom_point(shape=20) + labs(x="Year", y = "Anti-Environment Opinion") + 
  ylim(0.0,1.0) + theme_bw() + theme(axis.title.y = element_text(size = rel(1.2), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.2), angle = 00)) + 
  scale_colour_manual(values = c("env_dem_whosay_anti" = "gray80", "env_gop_whosay_anti" = "gray10", "env_ind_whosay_anti" = "gray40"), labels=c("Democrats", "Republicans", "Independents"), name = "") + theme(legend.position="bottom")

ggsave("Figure5B_Anti.pdf", width=6, height=6)

#### Figure 6 ####

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=pro_dem_change), colour="white") + scale_fill_gradient2(name ="Change in \nProportion", low="red",mid="white",high="blue",midpoint=0,  limits=c(-0.23,0.23)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Pro-Environment Opinion among Democrats", x="", y="") + theme(plot.title = element_text(size=23)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 13), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("Figure6A_Pro_Dem.pdf", width=11, height=5)

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=pro_gop_change), colour="white") + scale_fill_gradient2(name ="Change in \nProportion", low="red",mid="white",high="blue",midpoint=0,  limits=c(-0.23,0.23)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Pro-Environment Opinion among Democrats", x="", y="") + theme(plot.title = element_text(size=23)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 13), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("Figure6B_Pro_Gop.pdf", width=11, height=5)

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=pro_ind_change), colour="white") + scale_fill_gradient2(name ="Change in \nProportion", low="red",mid="white",high="blue",midpoint=0,  limits=c(-0.23,0.23)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Pro-Environment Opinion among Democrats", x="", y="") + theme(plot.title = element_text(size=23)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 13), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("Figure6C_Pro_Ind.pdf", width=11, height=5)

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=anti_dem_change), colour="white") + scale_fill_gradient2(name ="Change in \nProportion", low="blue",mid="white",high="red",midpoint=0,  limits=c(-0.23,0.23)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Pro-Environment Opinion among Democrats", x="", y="") + theme(plot.title = element_text(size=23)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 13), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("Figure6A2_Anti_Dem.pdf", width=11, height=5)

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=anti_gop_change), colour="white") + scale_fill_gradient2(name ="Change in \nProportion", low="blue",mid="white",high="red",midpoint=0,  limits=c(-0.23,0.23)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Pro-Environment Opinion among Democrats", x="", y="") + theme(plot.title = element_text(size=23)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 13), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("Figure6B2_Anti_Gop.pdf", width=11, height=5)

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=anti_ind_change), colour="white") + scale_fill_gradient2(name ="Change in \nProportion", low="blue",mid="white",high="red",midpoint=0,  limits=c(-0.23,0.23)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Pro-Environment Opinion among Democrats", x="", y="") + theme(plot.title = element_text(size=23)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 13), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("Figure6C2_Anti_Ind.pdf", width=11, height=5)

#### Figure 7 ####

ggplot(overtime_decade, aes(x=mean_dem_pro_73_82, y=mean_dem_pro_03_12)) + geom_point(shape=20) + labs(x="10-Year Average Pro-Environment Opinion among Democrats in 1973-82", y = "10-Year Average Pro-Environment Opinion among Democrats in 2003-12") + 
  xlim(0.45,0.75) + ylim(0.45,0.75) + geom_smooth(colour="black") + 
  theme_bw() + theme(axis.title.y = element_text(size = rel(0.95), angle = 90)) + theme(axis.title.x = element_text(size = rel(0.95), angle = 00)) + geom_abline(slope = 1, colour='grey')

ggsave("Figure7_Comparison_Pro_Dem.pdf", width=6, height=6)

ggplot(overtime_decade, aes(x=mean_gop_pro_73_82, y=mean_gop_pro_03_12)) + geom_point(shape=20) + labs(x="10-Year Average Pro-Environment Opinion among Republicans in 1973-82", y = "10-Year Average Pro-Environment Opinion among Republicans in 2003-12") + 
  xlim(0.379,0.57) + ylim(0.379,0.57)  + geom_smooth(colour="black") + 
  theme_bw() + theme(axis.title.y = element_text(size = rel(0.95), angle = 90)) + theme(axis.title.x = element_text(size = rel(0.95), angle = 00)) + geom_abline(slope = 1, colour='grey')

ggsave("Figure7_Comparison_Pro_Gop.pdf", width=6, height=6)

ggplot(overtime_decade, aes(x=mean_ind_pro_73_82, y=mean_ind_pro_03_12)) + geom_point(shape=20) + labs(x="10-Year Average Pro-Environment Opinion among Independents in 1973-82", y = "10-Year Average Pro-Environment Opinion among Independents in 2003-12") + 
  xlim(0.45,0.75) + ylim(0.45,0.75) + geom_smooth(colour="black") + 
  theme_bw() + theme(axis.title.y = element_text(size = rel(0.95), angle = 90)) + theme(axis.title.x = element_text(size = rel(0.95), angle = 00)) + geom_abline(slope = 1, colour='grey')

ggsave("Figure7_Comparison_Pro_Ind.pdf", width=6, height=6)

#### Figure 8 ####

ggplot(overtime_decade, aes(x=dem_change, y=pro_dem_change)) + geom_point(shape=20) + labs(x="Change in the Proportion of Democrats \n 1973-82 versus 2003-12", y = "Change in Pro-Environment Opinion among Democrats \n 1973-82 versus 2003-12") + 
  xlim(-0.35,0.35) + ylim(-0.35,0.35) + geom_smooth(colour="black") + #geom_text(aes(label=state_abb.1973), size=3, hjust=-0.4, vjust=-0.1) +
  theme_bw() + theme(axis.title.y = element_text(size = rel(1.1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.1), angle = 00)) + 
  geom_abline(slope = 1, colour='grey')

ggsave("Figure8_Dem.pdf", width=6, height=6)

ggplot(overtime_decade, aes(x=gop_change, y=pro_gop_change)) + geom_point(shape=20) + labs(x="Change in the Proportion of Democrats \n 1973-82 versus 2003-12", y = "Change in Pro-Environment Opinion among Democrats \n 1973-82 versus 2003-12") + 
  xlim(-0.35,0.35) + ylim(-0.35,0.35) + geom_smooth(colour="black") + #geom_text(aes(label=state_abb.1973), size=3, hjust=-0.4, vjust=-0.1) +
  theme_bw() + theme(axis.title.y = element_text(size = rel(1.1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.1), angle = 00)) + 
  geom_abline(slope = 1, colour='grey')

ggsave("Figure8_Gop.pdf", width=6, height=6)

ggplot(overtime_decade, aes(x=ind_change, y=pro_ind_change)) + geom_point(shape=20) + labs(x="Change in the Proportion of Democrats \n 1973-82 versus 2003-12", y = "Change in Pro-Environment Opinion among Democrats \n 1973-82 versus 2003-12") + 
  xlim(-0.35,0.35) + ylim(-0.35,0.35) + geom_smooth(colour="black") + #geom_text(aes(label=state_abb.1973), size=3, hjust=-0.4, vjust=-0.1) +
  theme_bw() + theme(axis.title.y = element_text(size = rel(1.1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.1), angle = 00)) + 
  geom_abline(slope = 1, colour='grey')

ggsave("Figure8_Ind.pdf", width=6, height=6)

#### Figure 9 ####

overtime_others_party <- overtime[c("state_abb", "year", "env_dem_whosay_pro", "aid_dem_whosay_pro", "arms_dem_whosay_pro", "educ_dem_whosay_pro", "welfare_dem_whosay_pro", "health_dem_whosay_pro", "race_dem_whosay_pro", 
                                                   "env_gop_whosay_pro", "aid_gop_whosay_pro", "arms_gop_whosay_pro", "educ_gop_whosay_pro", "welfare_gop_whosay_pro", "health_gop_whosay_pro", "race_gop_whosay_pro",
                                                   "env_ind_whosay_pro", "aid_ind_whosay_pro", "arms_ind_whosay_pro", "educ_ind_whosay_pro", "welfare_ind_whosay_pro", "health_ind_whosay_pro", "race_ind_whosay_pro")]
overtime_others_party$period <- ""
overtime_others_party[which(overtime_others_party$year> 1972 & overtime_others_party$year < 1983),]$period <- "year_73_82"
overtime_others_party[which(overtime_others_party$year> 2002 & overtime_others_party$year < 2013),]$period <- "year_03_12"
overtime_others_party <- subset(overtime_others_party, period!="")
overtime_others_party$year <- NULL

overtime_others_party <- aggregate(overtime_others_party, by=list(overtime_others_party$state_abb, overtime_others_party$period), FUN=mean, na.rm=TRUE)
overtime_others_party$period <- overtime_others_party$state_abb <- NULL
names(overtime_others_party)[1:2] <- c("state_abb", "period")

overtime_others_party <- reshape(overtime_others_party, idvar = c("state_abb", "period"), timevar = "group", times = names(overtime_others_party)[3:23], direction = "long", varying = list(names(overtime_others_party)[3:23]), v.names="pro", new.row.names = 1:2100)
overtime_others_party$grp <- paste(overtime_others_party$group, overtime_others_party$period)

overtime_others_party$var <- gsub("(.*)_(.*)_whosay_pro", "\\1", overtime_others_party$group, perl=T)

overtime_others_party$party <- gsub("(.*)_(.*)_whosay_pro", "\\2", overtime_others_party$group, perl=T)
overtime_others_party$party <- gsub("dem", "Democrat", overtime_others_party$party, perl=T)
overtime_others_party$party <- gsub("gop", "Republican", overtime_others_party$party, perl=T)
overtime_others_party$party <- gsub("ind", "Independent", overtime_others_party$party, perl=T)

overtime_others_party$color_grp <- paste(overtime_others_party$party, overtime_others_party$period)
overtime_others_party$color_grp <-  gsub("year_03_12", "2003-2012", overtime_others_party$color_grp, perl=T)
overtime_others_party$color_grp <-  gsub("year_73_82", "1973-1982", overtime_others_party$color_grp, perl=T)

overtime_others_party$grp <- Recode(overtime_others_party$grp, "'aid_dem_whosay_pro year_73_82'='1.75'; 'aid_ind_whosay_pro year_73_82'='1.85'; 'aid_gop_whosay_pro year_73_82'='1.95'; 'aid_dem_whosay_pro year_03_12'='2.05'; 'aid_ind_whosay_pro year_03_12'='2.15'; 'aid_gop_whosay_pro year_03_12'='2.25';
                                                                'race_dem_whosay_pro year_73_82'='2.75'; 'race_ind_whosay_pro year_73_82'='2.85'; 'race_gop_whosay_pro year_73_82'='2.95'; 'race_dem_whosay_pro year_03_12'='3.05'; 'race_ind_whosay_pro year_03_12'='3.15'; 'race_gop_whosay_pro year_03_12'='3.25';
                                                                'arms_dem_whosay_pro year_73_82'='3.75'; 'arms_ind_whosay_pro year_73_82'='3.85'; 'arms_gop_whosay_pro year_73_82'='3.95'; 'arms_dem_whosay_pro year_03_12'='4.05'; 'arms_ind_whosay_pro year_03_12'='4.15'; 'arms_gop_whosay_pro year_03_12'='4.25';
                                                                'educ_dem_whosay_pro year_73_82'='4.75'; 'educ_ind_whosay_pro year_73_82'='4.85'; 'educ_gop_whosay_pro year_73_82'='4.95';'educ_dem_whosay_pro year_03_12'='5.05'; 'educ_ind_whosay_pro year_03_12'='5.15'; 'educ_gop_whosay_pro year_03_12'='5.25';
                                                                'env_dem_whosay_pro year_73_82'='0.75'; 'env_ind_whosay_pro year_73_82'='0.85'; 'env_gop_whosay_pro year_73_82'='0.95';'env_dem_whosay_pro year_03_12'='1.05'; 'env_ind_whosay_pro year_03_12'='1.15'; 'env_gop_whosay_pro year_03_12'='1.25';
                                                                'health_dem_whosay_pro year_73_82'='5.75'; 'health_ind_whosay_pro year_73_82'='5.85'; 'health_gop_whosay_pro year_73_82'='5.95'; 'health_dem_whosay_pro year_03_12'='6.05'; 'health_ind_whosay_pro year_03_12'='6.15'; 'health_gop_whosay_pro year_03_12'='6.25';
                                                                'welfare_dem_whosay_pro year_73_82'='6.75'; 'welfare_ind_whosay_pro year_73_82'='6.85'; 'welfare_gop_whosay_pro year_73_82'='6.95';'welfare_dem_whosay_pro year_03_12'='7.05'; 'welfare_ind_whosay_pro year_03_12'='7.15'; 'welfare_gop_whosay_pro year_03_12'='7.25'")

overtime_others_party <- overtime_others_party[order(overtime_others_party$period, overtime_others_party$var, overtime_others_party$party, -rank(overtime_others_party$pro)),]
overtime_others_party$rank <- rep(c(1:50), 42)

ggplot(overtime_others_party, aes(x=grp, y=pro, shape=color_grp, color=color_grp)) + geom_point(size=1.6) + scale_shape_manual(values=c(19, 17, 19, 17, 19, 17), name="") + scale_colour_manual(values = c("gray75", "gray75", "gray40", "gray40", "gray10", "gray10"), name="") +
  scale_x_continuous(breaks = c(1,2,3,4,5,6,7), labels = c("Environment", "Aid", "Blacks", "Defense", "Education", "Health", "Welfare"), limits=c(0.3, 7.5)) +
  ylim(0, 0.815) + xlab("") + theme_bw() + theme(legend.position="bottom") + ylab("Pro-Spending Opinion") + theme(axis.text.x = element_text(size=c(10.5,9,9,9,9,9,9))) + 
  theme(panel.grid.major.x = element_blank())  + geom_vline(xintercept = c(2.5,3.5,4.5,5.5,6.5,7.5), linetype="dotted", color = "gray80", size=0.5) + geom_vline(xintercept = c(0.5,1.5), linetype="dotted", color = "gray50", size=0.5) +
  theme(axis.ticks.x=element_blank())

ggsave("Figure9_Others.pdf", width=8, height=5)

#### Figure A1 ####

ggplot(subset(overtime, year==1976), aes(y=env_pro, x=reorder(state_abb, env_pro))) + geom_point() +
  coord_flip() + geom_errorbar(aes(ymin=env_pro_uncertainty_lower, ymax=env_pro_uncertainty_upper)) + 
  scale_y_continuous(breaks = c(0, 0.25, 0.5, 0.75, 1), limits=c(0,1)) + 
  ylab("Estimation of Pro-Environment Opinion by State in 1976") + xlab("") + 
  theme(axis.text.y = element_text(size=11)) + theme(axis.text.x = element_text(size=12)) + theme(axis.title.x = element_text(size = 15))

ggsave("FigureA1_1976.pdf", width=6, height=8.5)

ggplot(subset(overtime, year==1986), aes(y=env_pro, x=reorder(state_abb, env_pro))) + geom_point() +
  coord_flip() + geom_errorbar(aes(ymin=env_pro_uncertainty_lower, ymax=env_pro_uncertainty_upper)) + 
  scale_y_continuous(breaks = c(0, 0.25, 0.5, 0.75, 1), limits=c(0,1)) + 
  ylab("Estimation of Pro-Environment Opinion by State in 1986") + xlab("") +
  theme(axis.text.y = element_text(size=11)) + theme(axis.text.x = element_text(size=12)) + theme(axis.title.x = element_text(size = 15))

ggsave("FigureA1_1986.pdf", width=6, height=8.5)

ggplot(subset(overtime, year==1996), aes(y=env_pro, x=reorder(state_abb, env_pro))) + geom_point() +
  coord_flip() + geom_errorbar(aes(ymin=env_pro_uncertainty_lower, ymax=env_pro_uncertainty_upper)) + 
  scale_y_continuous(breaks = c(0, 0.25, 0.5, 0.75, 1), limits=c(0,1)) + 
  ylab("Estimation of Pro-Environment Opinion by State in 1996") + xlab("") +
  theme(axis.text.y = element_text(size=11)) + theme(axis.text.x = element_text(size=12)) + theme(axis.title.x = element_text(size = 15))

ggsave("FigureA1_1996.pdf", width=6, height=8.5)

ggplot(subset(overtime, year==2006), aes(y=env_pro, x=reorder(state_abb, env_pro))) + geom_point() +
  coord_flip() + geom_errorbar(aes(ymin=env_pro_uncertainty_lower, ymax=env_pro_uncertainty_upper)) + 
  scale_y_continuous(breaks = c(0, 0.25, 0.5, 0.75, 1), limits=c(0,1)) + 
  ylab("Estimation of Pro-Environment Opinion by State in 2006") + xlab("") +
  theme(axis.text.y = element_text(size=11)) + theme(axis.text.x = element_text(size=12)) + theme(axis.title.x = element_text(size = 15))

ggsave("FigureA1_2006.pdf", width=6, height=8.5)

#### Figure A2 ####

# Map with Anti-Enviornmental Opinion in 1973-1982 

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=anti_10_pt_73_82), colour="white") + scale_fill_continuous(name = "Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,1.0), labels=c("0.07", "0.10", "0.11", "0.12", "0.15")) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm")) 

ggsave("FigureA2_1972_83.pdf", width=11, height=5)

# Map with Anti-Enviornmental Opinion in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=anti_10_pt_03_12), colour="white") + scale_fill_continuous(name = "Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,1.0), labels=c("0.07", "0.10", "0.11", "0.12", "0.15")) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm")) 

ggsave("FigureA2_2003_12.pdf", width=11, height=5)

# Map with Change in Anti-Enviornmental Opinion 

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=anti_change), colour="white") + scale_fill_gradient2(name = "Change in \nProportion", low="blue",mid="white",high="red",midpoint=0, limits=c(-0.12,0.12)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Change in Average Anti-Environment Opinion", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA2_Change.pdf", width=11, height=5)

#### Figure A3 ####

# Map with Pro-Enviornmental Opinion among Democrats in 1973-1982 

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_dem_pro_73_82), colour="white") + scale_fill_continuous(name="Proportion", low="burlywood4", high="aquamarine3", guide="colorbar", limits=c(0.35,0.75)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion among Democrats in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA3_Pro_Dem_1973_82.pdf", width=11, height=5)

# Map with Pro-Enviornmental Opinion among Republicans in 1973-1982 

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_gop_pro_73_82), colour="white") + scale_fill_continuous(name="Proportion", low="burlywood4", high="aquamarine3", guide="colorbar", limits=c(0.35,0.75)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion among Republicans in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA3_Pro_Gop_1973_82.pdf", width=11, height=5)

# Map with Pro-Enviornmental Opinion among Independents in 1973-1982 

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_ind_pro_73_82), colour="white") + scale_fill_continuous(name="Proportion", low="burlywood4", high="aquamarine3", guide="colorbar", limits=c(0.35,0.75)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion among Independents in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA3_Pro_Ind_1973_82.pdf", width=11, height=5)

# Map with Pro-Enviornmental Opinion among Democrats in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_dem_pro_03_12), colour="white") + scale_fill_continuous(name="Proportion", low="burlywood4", high="aquamarine3", guide="colorbar", limits=c(0.35,0.75)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion among Democrats in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA3_Pro_Dem_2003_12.pdf", width=11, height=5)

# Map with Pro-Enviornmental Opinion among Republicans in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_gop_pro_03_12), colour="white") + scale_fill_continuous(name="Proportion", low="burlywood4", high="aquamarine3", guide="colorbar", limits=c(0.35,0.75)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion among Republicans in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA3_Pro_Gop_2003_12.pdf", width=11, height=5)

# Map with Pro-Enviornmental Opinion among Independents in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_ind_pro_03_12), colour="white") + scale_fill_continuous(name="Proportion", low="burlywood4", high="aquamarine3", guide="colorbar", limits=c(0.35,0.75)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Pro-Environment Opinion among Independents in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA3_Pro_Ind_2003_12.pdf", width=11, height=5)

#### Figure A4 ####

# Map with Anti-Enviornmental Opinion among Democrats in 1973-1982

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_dem_anti_73_82), colour="white") + scale_fill_continuous(name="Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,0.2)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion among Democrats in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA4_Anti_Dem_1973_82.pdf", width=11, height=5)

# Map with Anti-Enviornmental Opinion among Republicans in 1973-1982

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_gop_anti_73_82), colour="white") + scale_fill_continuous(name="Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,0.2)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion among Republicans in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA4_Anti_Gop_1973_82.pdf", width=11, height=5)

# Map with Anti-Enviornmental Opinion among Independents in 1973-1982

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_ind_anti_73_82), colour="white") + scale_fill_continuous(name="Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,0.2)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion among Independents in 1973-1982", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA4_Anti_Ind_1973_82.pdf", width=11, height=5)

# Map with Anti-Enviornmental Opinion among Democrats in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_dem_anti_03_12), colour="white") + scale_fill_continuous(name="Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,0.2)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion among Democrats in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA4_Anti_Dem_2003_12.pdf", width=11, height=5)

# Map with Anti-Enviornmental Opinion among Republicans in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_gop_anti_03_12), colour="white") + scale_fill_continuous(name="Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,0.2)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion among Republicans in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA4_Anti_Gop_2003_12.pdf", width=11, height=5)

# Map with Anti-Enviornmental Opinion among Independents in 2003-2012

ggplot() + geom_polygon(data=data_map, aes(x=long, y=lat, group=group, fill=mean_ind_anti_03_12), colour="white") + scale_fill_continuous(name="Proportion", low="aquamarine3", high="burlywood4", guide="colorbar", limits=c(0.0,0.2)) +
  coord_map("albers", lat0=30, lat1=40) + borders("state") + theme_bw() + labs(fill="", title = "Average Anti-Environment Opinion among Independents in 2003-2012", x="", y="") + theme(plot.title = element_text(size=15)) +
  scale_y_continuous(breaks=c()) + scale_x_continuous(breaks=c()) + theme(panel.border =  element_blank()) + theme(legend.title = element_text(size = 11), legend.text = element_text(size = 11), legend.key.size = unit(1, "cm"))

ggsave("FigureA4_Anti_Ind_2003_12.pdf", width=11, height=5)

#### Figure A5 ####

ggplot(pro_df[which(pro_df$variable=="difference"),], aes(x=year, y=value)) + geom_point(shape=20) + labs(x="Year", y = "Partisan Polarization (Pro-Environment Opinion)") + 
  ylim(-0.01,0.3) + theme_bw() + theme(axis.title.y = element_text(size = rel(1.2), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.2), angle = 00)) + 
  theme(legend.position="bottom")

ggsave("FigureA5_Pro_Polarization.pdf", width=6, height=6)

ggplot(anti_df[which(anti_df$variable=="difference"),], aes(x=year, y=value)) + geom_point(shape=20) + labs(x="Year", y = "Partisan Polarization (Anti-Environment Opinion)") + 
  ylim(-0.02,0.3) + theme_bw() + theme(axis.title.y = element_text(size = rel(1.2), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.2), angle = 00)) + 
  theme(legend.position="bottom")

ggsave("FigureA5_Anti_Polarization.pdf", width=6, height=6)

#### Figure A6 ####

ggplot(overtime_decade, aes(x=dem_change, y=anti_dem_change)) + geom_point(shape=20) + labs(x="Change in the Proportion of Democrats \n 1973-82 versus 2003-12", y = "Change in Anti-Environment Opinion among Democrats \n 1973-82 versus 2003-12") + 
  xlim(-0.35,0.35) + ylim(-0.35,0.35) + geom_smooth(colour="black") + theme_bw() + theme(axis.title.y = element_text(size = rel(1.1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.1), angle = 00)) + geom_abline(slope = 1, colour='grey')

ggsave("FigureA6_Dem.pdf", width=6, height=6)

ggplot(overtime_decade, aes(x=gop_change, y=anti_gop_change)) + geom_point(shape=20) + labs(x="Change in the Proportion of Republicans \n 1973-82 versus 2003-12", y = "Change in Anti-Environment Opinion among Republicans \n 1973-82 versus 2003-12") + 
  xlim(-0.35,0.35) + ylim(-0.35,0.35) + geom_smooth(colour="black") + theme_bw() + theme(axis.title.y = element_text(size = rel(1.1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.1), angle = 00)) + geom_abline(slope = 1, colour='grey')

ggsave("FigureA6_Gop.pdf", width=6, height=6)

ggplot(overtime_decade, aes(x=ind_change, y=anti_ind_change)) + geom_point(shape=20) + labs(x="Change in the Proportion of Independents \n 1973-82 versus 2003-12", y = "Change in Anti-Environment Opinion among Independents \n 1973-82 versus 2003-12") + 
  xlim(-0.35,0.35) + ylim(-0.35,0.35) + geom_smooth(colour="black") + theme_bw() + theme(axis.title.y = element_text(size = rel(1.1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1.1), angle = 00)) + geom_abline(slope = 1, colour='grey')

ggsave("FigureA6_Ind.pdf", width=6, height=6)

#### Figure A7 ####

overtime_others <- overtime[c("state_abb", "year", "env_pro", "aid_pro", "arms_pro", "educ_pro", "welfare_pro", "health_pro", "race_pro")]
overtime_others$period <- ""
overtime_others[which(overtime_others$year> 1972 & overtime_others$year < 1983),]$period <- "year_73_82"
overtime_others[which(overtime_others$year> 2002 & overtime_others$year < 2013),]$period <- "year_03_12"
overtime_others <- subset(overtime_others, period!="")
overtime_others$year <- NULL

overtime_others <- aggregate(overtime_others, by=list(overtime_others$state_abb, overtime_others$period), FUN=mean, na.rm=TRUE)
overtime_others$period <- overtime_others$state_abb <- NULL
names(overtime_others)[1:2] <- c("state_abb", "period")

overtime_others <- reshape(overtime_others, idvar = c("state_abb", "period"), timevar = "group", times = names(overtime_others)[3:9], direction = "long", varying = list(names(overtime_others)[3:9]), v.names="pro", new.row.names=1:700)

overtime_others$group <- Recode(overtime_others$group, "'aid_pro'='Aid'; 'educ_pro'='Education'; 'health_pro'='Health'; 'welfare_pro'='Welfare'; 'arms_pro'='Defense'; 'env_pro'='Environment'; 'race_pro'='Blacks'")
overtime_others <- overtime_others[order(overtime_others$period, overtime_others$group, -rank(overtime_others$pro)),]
overtime_others$rank <- 0
overtime_others[which(overtime_others$group=="Environment"),]$rank <- c(100:1)

ggplot(overtime_others[which(overtime_others$period=="year_73_82"),]) + aes(x=pro, y=reorder(state_abb, rank, max), by=group) + geom_point(aes(color = factor(group)))  + 
  theme_bw() + theme(legend.position="bottom") + scale_x_continuous(breaks = c(0, 0.25, 0.5, 0.75), limits=c(0,0.75)) +
  scale_colour_manual("", values = c("#FF67A4", "#B983FF", "#619CFF", "#00B0F6", "#00BA38", "#E58700", "#F8766D")) + 
  guides(fill=guide_legend(ncol=7))  + xlab("Pro-Spending Opinion, 1973-1982") + ylab("")

ggsave("FigureA7_1973_82.pdf", width=6, height=8.5)

ggplot(overtime_others[which(overtime_others$period=="year_03_12"),]) + aes(x=pro, y=reorder(state_abb, rank, max), by=group) + geom_point(aes(color = factor(group)))  + 
  theme_bw() + theme(legend.position="bottom") + scale_x_continuous(breaks = c(0, 0.25, 0.5, 0.75), limits=c(0,0.75)) +
  scale_colour_manual("", values = c("#FF67A4", "#B983FF", "#619CFF", "#00B0F6", "#00BA38", "#E58700", "#F8766D")) + 
  guides(fill=guide_legend(ncol=7))  + xlab("Pro-Spending Opinion, 1973-1982") + ylab("")

ggsave("FigureA7_2003_12.pdf", width=6, height=8.5)
